package com.tanhua.sso.vo;

import cn.hutool.core.convert.Convert;
import com.tanhua.sso.pojo.Movement;
import com.tanhua.sso.pojo.UserInfo;
import com.tanhua.sso.utils.RelativeDateFormat;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.util.StringUtils;

import java.io.Serializable;
import java.util.Date;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class ManageMovementsVo implements Serializable {
    private String id; //动态id

    private Integer userId; //用户id
    private String avatar; //头像
    private String nickname; //昵称

    private String textContent; //文字动态
    private String[] imageContent; //图片动态
    private Long createDate; //发布时间 如: 10分钟前
    private Integer likeCount; //点赞数
    private Integer commentCount; //评论数
    private String state;  //审核状态

    //数据封装
    public static ManageMovementsVo init(UserInfo userInfo, Movement item) {
        ManageMovementsVo vo = new ManageMovementsVo();
        //设置动态数据
        BeanUtils.copyProperties(userInfo, vo);
        BeanUtils.copyProperties(item,vo);
        //用户id
        vo.setUserId(Convert.toInt(userInfo.getId()));
        //时间
        vo.setCreateDate(item.getCreated());
        //图片
        vo.setImageContent(item.getMedias().toArray(new String[]{}));
        vo.setId(item.getId().toHexString());
        return vo;
    }

}
